package com.hoshiicloud.withdraw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hoshiicloud.withdraw.entity.UserContractPlatformRecord;
import com.hoshiicloud.withdraw.entity.UserInfo;
import com.hoshiicloud.withdraw.mapper.UserContractPlatformRecordMapper;
import com.hoshiicloud.withdraw.mapper.UserInfoMapper;
import com.hoshiicloud.withdraw.param.ElectronicContractCallbackParam;
import com.hoshiicloud.withdraw.param.SubscriptionInformatioParam;
import com.hoshiicloud.withdraw.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (UserInfo)表服务实现类
 *
 * @author makejava
 * @since 2019-08-21 17:31:42
 */
@Service("userInfoService")
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

	@Autowired
	private UserInfoMapper userInfoMapper;

	@Autowired
	private UserContractPlatformRecordMapper userContractPlatformRecordMapper;

	@Override
	public Boolean subscriptionInformation(SubscriptionInformatioParam param) {
		Integer contractStatus = userInfoMapper.subscriptionInformation(param);
		// 当没有记录和 等于1 时 返回false
		return contractStatus != null && contractStatus != 1;
	}

	@Override
	public void electronicContractInfo(ElectronicContractCallbackParam param) {

		UserContractPlatformRecord.builder().id(Integer.parseInt(param.getExtraParam())).status(param.getStatus()).bankName(param.getBankName()).build().updateById();
		// 根据三方回调写入状态

		// 将用户信息 标注为签约成功状态
		QueryWrapper<UserInfo> userInfoQueryWrapper = new QueryWrapper<>();
		userInfoQueryWrapper.lambda().eq(UserInfo::getName, param.getName())
				.eq(UserInfo::getIsDel, 0)
				.eq(UserInfo::getIdcard, param.getIdentity());
		UserInfo userInfo = this.getOne(userInfoQueryWrapper);
		userInfo.setContractStatus(param.getStatus());
		userInfo.setBankName(param.getBankName());
		this.updateById(userInfo);
	}

	@Override
	public String contractRecord(SubscriptionInformatioParam param) {
		return userInfoMapper.contractRecord(param);
	}
}